// import { message } from 'ant-design-vue';
import markerName from '../map-marker/enum/marker-name.js';
import { MapInfoWindow } from './index.js';
import { dialog } from '@gis/lib/components/antd-dialog';
import { createElem } from '@gis/lib/utils/domUtils.js';
import { NONE_TEXT } from '@gis/lib/config/index.js';
import { getMonitorDetail } from '@gis/lib/api/index.js';
import { handleCommonResult } from '@gis/lib/utils/resolver.js';
// import { openPeopleDetailsDialog } from '@/views/reality-people/components/people-details/peopleDetailsDialog.js';

function getText(data = {}, key, dft = NONE_TEXT) {
  return data ? data[key] || dft : dft;
}

function isCamera(code) {
  return code === 'ptjk' || /^D0112_\d+/.test(code);
}

export default class extends MapInfoWindow {
  constructor({ map }) {
    super({ map });
  }

  getTitle() {
    const data = this.getData();
    return markerName(data.type_code) || '详情';
  }

  getContent() {
    const data = this.getData();
    // console.log(data, "详情");
    if (['mj', 'dz'].indexOf(data.type_code) >= 0) {
      return createElem('div', {
        class: 'info-content',
        children: [
          createElem('div', { children: `名称：${getText(data, 'name')}` }),
          createElem('div', { children: `所属小区：${getText(data, 'yard_name')}` }),
          createElem('div', { children: `设备序列号：${getText(data, 'identification')}` }),
          createElem('div', { children: `负责人姓名：${getText(data, 'installers')}` }),
          createElem('div', { children: `负责人电话：${getText(data, 'installers_phone')}` }),
          createElem('div', { children: `安装时间：${getText(data, 'installation_time')}` }),
        ],
      });
    }
    if (isCamera(data.type_code)) {
      return createElem('div', {
        class: 'info-content',
        children: [createElem('div', { children: `名称：${getText(data, 'name')}` })],
      });
    }
    if (['znsh'].indexOf(data.type_code) >= 0) {
      return createElem('div', {
        class: 'info-content',
        style: 'position: relative',
        children: [
          createElem('img', {
            src: `${getText(data, 'head_img_url')}`,
            style: 'width: 50px;height: 62px;position: absolute;top: 20px;right: 20px',
          }),
          createElem('div', { children: `姓名：${getText(data, 'name')}` }),
          createElem('div', { children: `证件号：${getText(data, 'identity_num')}` }),
          createElem('div', { children: `收缩压：${getText(data, 'sbp')}` }),
          createElem('div', { children: `舒张压：${getText(data, 'dbp')}` }),
          createElem('div', { children: `心率：${getText(data, 'heartrate')}` }),
          createElem('div', { children: `数据更新时间：${getText(data, 'create_time')}` }),
        ],
      });
    }
    if (['7_01'].indexOf(data.type_code) >= 0) {
      return createElem('div', {
        class: 'info-content',
        children: [
          createElem('div', { children: `姓名：${getText(data, 'name')}` }),
          createElem('div', { children: `类型：${getText(data, 'category_name')}` }),
          createElem('div', { children: `负责人姓名：${getText(data, 'manager_name')}` }),
          createElem('div', { children: `负责人电话：${getText(data, 'manager_phone')}` }),
          createElem('div', { children: `地址：${getText(data, 'address')}` }),
        ],
      });
    }
    return createElem('div', {
      class: 'info-content',
      children: [createElem('div', { children: `名称：${getText(data, 'name')}` })],
    });
  }

  getFooter() {
    const data = this.getData();
    if (isCamera(data.type_code)) {
      const showVideo = createElem('button', { class: 'ant-btn', children: '查看视频' });
      showVideo.onclick = () => this.showVideo();
      return showVideo;
    }
    if (data.type_code === 'znsh') {
      const showPeopleDetail = createElem('button', { class: 'ant-btn', children: '查看人员详情' });
      showPeopleDetail.onclick = () => this.showPeopleDetail();
      return showPeopleDetail;
    }
  }

  //智能手环 - 查看人员详情
  showPeopleDetail() {
    const data = this.getData();
    // debugger;
    // openPeopleDetailsDialog(data);
  }
  //普通监控 - 查看视频
  async showVideo() {
    const data = this.getData();
    const attrs = await this.getCameraDetails(data.id);
    dialog({
      content: () => import('@gis/lib/components/player/index.jsx'),
      contentProps: {
        data: attrs,
      },
      dialogProps: {
        title: '查看视频',
        width: 900,
        height: 600,
        footer: null,
      },
    });
  }
  async getCameraDetails(monitor_id) {
    const res = await getMonitorDetail({ monitor_id }).catch(() => null);
    return handleCommonResult(res);
  }
}
